<template>
  <view class>
    <view class="item" v-if="type==1">
      <view class="item-p1">临停缴费</view>
      <view class="item-p4">
        <text>车场：</text>
        <text>{{orderDetails.park.parkName}}</text>
      </view>
      <view class="item-p4">
        <text>订单号：</text>
        <text>{{orderDetails.id}}</text>
      </view>
      <view class="item-p4">
        <text>车牌：</text>
        <text>{{orderDetails.carNo}}</text>
      </view>
      <view class="item-p4">
        <text>入场时间：</text>
        <text>{{orderDetails.startTime}}</text>
      </view>
      <view class="item-p4">
        <text>出场时间：</text>
        <text>{{orderDetails.endTime}}</text>
      </view>
      <view class="item-p4">
        <text>停车时长：</text>
        <text>{{orderDetails.parlLong}}</text>
      </view>
      <view class="item-p4">
        <text>停车总金额：</text>
        <text>{{orderDetails.amount/100}}元</text>
      </view>
      <view class="item-p4">
        <text>优惠金额：</text>
        <text v-if="orderDetails.discountAmount>orderDetails.amount">{{orderDetails.amount/100}}元</text>
        <text v-else>{{orderDetails.discountAmount/100}}元</text>
      </view>
      <view class="item-p4">
        <text>实付金额：</text>
        <text>{{orderDetails.payAmount/100}}元</text>
      </view>
      <view class="item-p4">
        <text>交易时间：</text>
        <text>{{orderDetails.payTime}}</text>
      </view>
    </view>
    <view v-if="type==2" class="item">
        <view class="item-p1">{{orderDetails.carType=='1'?'月租':"储值"}}缴费</view>
        <view class="item-p4">
          <text>车场：</text>
          <text>{{orderDetails.park.parkName}}</text>
        </view>
        <view class="item-p4">
          <text>订单号：</text>
          <text>{{orderDetails.id}}</text>
        </view>
        <!-- <view class="item-p4">
          <text>车牌：</text>
          <text>{{orderDetails.carNo}}</text>
        </view> -->
        <view class="item-p4">
          <text>时间：</text>
          <text>{{orderDetails.payTime}}</text>
        </view>
        <view class="item-p4" v-if="orderDetails.carType=='1'">
          <text>续费有效开始时间：</text>
          <text>{{orderDetails.startTime.substring(0,10)}}</text>
        </view>
        <view class="item-p4" v-if="orderDetails.carType=='1'">
          <text>续费有效结束时间：</text>
          <text>{{orderDetails.endTime.substring(0,10)}}</text>
        </view>
        <view class="item-p4">
          <text>优惠金额：</text>
          <text>{{orderDetails.discountAmount/100}}元</text>
        </view>
        <view class="item-p4">
          <text>实付金额：</text>
          <text>{{orderDetails.payAmount/100}}元</text>
        </view>
        <view class="item-p4">
          <text>总金额：</text>
          <text>{{orderDetails.amount/100}}元</text>
        </view>
    </view>
  </view>
</template>
<script>
import Taro from "@tarojs/taro";
import { setGlobalData, getGlobalData } from "../../globalData.js";
import "./orderListDetail.less";
import bulterApi from "@souche2014/bulter-api";
const api = bulterApi({ partner: "IOParking" });
export default {
  data() {
    return {
      loading: true,
      apiBaseUrl: process.env.IOParking.API_HOST, //请求头
      url: "",
      orderDetails: [],
      id: 0,
      type: 0,
      money:0,
    };
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.type = options.type;
    this.id = options.id;
    if (options.type == 1) {
      this.url = this.apiBaseUrl + "/parkingpayment/tempparkingrecorddetail"; //临停
    }
    if (options.type == 2) {
      this.url = this.apiBaseUrl + "/parkingpayment/renewrecorddetail"; //充值
    }
    this.initData(options.id);
  },
  methods: {
    initData: function(id) {
      Taro.showLoading({
        title: "加载中",
        mask: true
      });
      var that = this;
      var base = this.apiBaseUrl;
      that.loading = true;
      Taro.request({
        url: that.url + "?id=" + this.id,

        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          Taro.hideLoading();
          that.loading = false;
          if (res.data.isSuccess) {
            console.log(res.data.data);
            that.orderDetails = res.data.data;
           
          }
        }
      });
    },
     num(a) {
      if (a != null && a.toString() != "") {
        let r = /^-?(0|[1-9]+\d*|[1-9]+\d*\.\d+|0\.\d+)$/;
        if (r.test(a.toString())) {
          return true;
        }
      }
      return false;
    },
    //减法
    minus(a, b) {
      if (!this.num(a) || !this.num(b)) {
        return null;
      }
      let c, d, m, n;
      try {
        c = a.toString().split(".")[1].length;
      } catch (e) {
        c = 0;
      }
      try {
        d = b.toString().split(".")[1].length;
      } catch (e) {
        d = 0;
      }
      m = Math.pow(10, Math.max(c, d));
      return (a * m - b * m) / m;
    },
  }
};
</script>